﻿using DocumentMaking.Lib.Services;

namespace DocumentMaking.Lib.Models;

public class MemberModel
{
    public string Name { get; set; }
    public string ID { get; set; }

    public bool IsOk()
    {
        return IDVerificationService.CheckId(Name) && IDVerificationService.CheckName(ID);
    }
}

public class IdCardModel
{
    public string Id { get; set; }
    public string AddressCode { get; set; }
    public string Address { get; set; }
    public string BirthdayCode { get; set; }
    public string OrderCode { get; set; }
    public string CheckBit { get; set; }
    private int Type { get; set; }
    public string Name { get; set; }

    public IdCardModel(MemberModel model)
    {
        Name = model.Name;
        Id = model.ID.ToUpper();
        Type = Id.Length;
        Address = IDVerificationService.GetAddress(Id) ?? "";
        if (Type == 18)
        {
            AddressCode = Id[..6];
            BirthdayCode = Id[6..14];
            OrderCode = Id[14..17];
            CheckBit = Id[^1].ToString();
            return;
        }

        AddressCode = Id[..6];
        BirthdayCode = Id[6..12];
        OrderCode = Id[12..15];
        CheckBit = "";
    }
}